using AiQiuQuan.Sport.Model.Models;
using AiQiuQuan.Sport.Core;
using AiQiuQuan.Sport.WebApi.Services;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Authorization;

namespace AiQiuQuan.Sport.WebApi.Controllers
{
    /// <summary>
    /// 约球管理
    /// </summary>
    public class BallController : ApiController
    {
        private readonly IBallService _ballService;

        /// <summary>
        /// 约球管理
        /// </summary>
        public BallController(
            IBallService ballService
            )
        {
            _ballService = ballService;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="id">约球ID</param>
        [HttpGet("get")]
        public async Task<UnaryResult<BallDto>> GetAsync([Required] Guid id)
        {
            var result = await _ballService.GetAsync(id);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 约球查询
        /// </summary>
        [HttpPost("query")]
        public async Task<UnaryResult<BallDto>> QueryAsync(BallQueryDto request)
        {
            var result = await _ballService.QueryAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        [HttpPost("pagelist")]
        [AllowAnonymous]
        public async Task<UnaryResult<PageResult<BallDto>>> PageListAsync(BallPageRequestDto request)
        {
            var result = await _ballService.PageListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 获取自己参与的约球列表
        /// </summary>
        [HttpPost("pagelist_self")]
        public async Task<UnaryResult<PageResult<BallDto>>> GetMyBallPageListAsync(BallSelfPageRequestDto request)
        {
            var result = await _ballService.GetMyBallPageListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost("add")]
        public async Task<UnaryResult> AddAsync(BallAddDto model)
        {
            var result = await _ballService.AddAsync(model);
            return result;
        }

        /// <summary>
        /// 修改
        /// </summary>
        [HttpPost("update")]
        public async Task<UnaryResult> UpdateAsync(BallUpdateDto model)
        {
            var result = await _ballService.UpdateAsync(model);
            return result;
        }

        /// <summary>
        /// 修改约球状态
        /// </summary>
        [HttpPost("update_state")]
        public async Task<UnaryResult> UpdateStateAsync(BallStateUpdateDto request)
        {
            var result = await _ballService.UpdateStateAsync(request);
            return result;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">约球ID</param>
        [HttpGet("delete")]
        public async Task<UnaryResult> DeleteAsync([Required] Guid id)
        {
            var result = await _ballService.DeleteAsync(id);
            return result;
        }

        /// <summary>
        /// 约球报名
        /// </summary>
        [HttpPost("join")]
        public async Task<UnaryResult<BallJoinResultDto>> JoinAsync(BallUserJoinAddDto request)
        {
            var result = await _ballService.JoinAsync(request);
            return result;
        }

        /// <summary>
        /// 获取约球用户列表
        /// </summary>
        [HttpPost("list_join_user")]
        public async Task<UnaryResult<List<BallUserDto>>> GetBallUserListAsync(BallUserQueryDto request)
        {
            var result = await _ballService.GetBallUserListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 约球用户评价
        /// </summary>
        [HttpPost("evalulate_user")]
        public async Task<UnaryResult> EvalulateUserAsync(BallEvaluationAddDto request)
        {
            var result = await _ballService.EvalulateUserAsync(request);
            return result;
        }

        /// <summary>
        /// 获取约球用户评价
        /// </summary>
        [HttpPost("list_evalulation")]
        public async Task<UnaryResult<List<BallEvaluationDto>>> GetBallEvalulationListAsync(BallEvaluationRequestDto request)
        {
            var result = await _ballService.GetBallEvalulationListAsync(request);
            return UnaryResult.Succeed(result);
        }
    }
}
